<?php include_once('header.php'); ?>
<?php include_once('left_navigation.php'); ?>
<style type="text/css">
	.datepicker{
		z-index: 99999999999;
	}
</style>
<?php
	
		include('../classess/latest_news.php');

		$new_news = new latest_news();
		
		if(isset($_POST['ltst_nws_txtarea'])  && trim($_POST['ltnws_id'])=='' ){		
			$add_update_latset_news = $new_news->ltst_nws_add(); 
		}

		if(isset($_POST['ltnws_id']) && trim($_POST['ltnws_id'])!=''){
			$add_update_latset_news = $new_news->update_ltst_nws(); 
		}
		
		$id = "";
		$l_news = "";
		$select_news = "SELECT * FROM tbl_latest_news";
		$query_news = mysql_query($select_news) or die(mysql_error());

		if(mysql_num_rows($query_news) > 0){
			while($row_news = mysql_fetch_array($query_news)){
				$id = $row_news['id'];
				$l_news = $row_news['latest_news'];
			}
		}
?>
	<div class="col-lg-12"><!-- Start Middle Content Div-->
		<div class="box">
			
			<div class="box-header" data-original-title=""><!-- Start Box Header Div-->
				<h2><i class="fa fa-edit"></i><span class="break"></span><?php if($id!=''){ echo 'Edit '; }else{echo 'Add '; }?> Latest News</h2>
				<div class="box-icon">
					<a href="gallery.html#" class="btn-minimize"><i class="fa fa-chevron-up"></i></a>
					<a href="gallery.html#" class="btn-close"><i class="fa fa-times"></i></a>
				</div>
			</div><!-- End Box Header Div-->
			<div class="box-content"><!-- Start Box Content Div-->
				<div class="row">
					
					<div class="col-sm-12">
						<?php 
							if(isset($add_update_latset_news)){	
						?>
						<div class="alert alert-info">
							<div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>
							<div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $add_update_latset_news; ?></div>
							<div style="clear:both;"></div>							
						</div>
						<?php
							}
						?>
						<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?ltst_nws=1" name="ltst_news_form" id="ltst_news_form" enctype="multipart/form-data">
							<div class="main_form_box col-sm-6">
								<div class="form-content  form-content-form">								
									
									<label>Latest News</label>
									<textarea placeholder="Latest News" name="ltst_nws_txtarea" id="ltst_nws_txtarea">
										<?php echo $l_news; ?>  </textarea>
								</div>
							</div>
							<div class="main_form_box col-sm-6">
								<div class="form-content  form-content-form">
									<label style="text-align:right;">
										<button type="button" class="btn btn-blue login_button" name="add_ltst_nws" id="add_ltst_nws"><?php if($id!=''){ echo 'Edit'; }else{echo 'Add'; }?></button> 							
									</label>

									<input type="hidden" name="ltnws_id" id="ltnws_id" value="<?php if($id!=''){ echo $id; } ?>">
								</div>
							</div>							
							<div style="clear:both;"></div>							
						</form>

					</div><!--/col-->
				</div><!-- End Row div -->
			</div><!-- End Box Content Div -->

		</div><!-- End Box Div-->
	</div><!-- End Middle Content Div-->	
<?php include_once('footer.php'); ?>
<script type="text/javascript" src="inner_js/bootstrap-datepicker.min.js"></script>
<script>
	$ = jQuery.noConflict();
	$(document).ready(function(){	
		$('#add_ltst_nws').click(function(){
			if($('textarea#ltst_nws_txtarea').val().trim() == ''){			
				alert("Please enter a value for the \" Latest News\" field.");
				$('textarea#ltst_nws_txtarea').focus();
				return (false);
			}
			else{
				document.ltst_news_form.submit();
			}
		});

		$('.close').click(function(){
			$('.alert-info').addClass('hide');
		});
	});		
	
</script>